import { Get, Post, Body, Put, Delete, Param, Controller, UsePipes, HttpStatus } from '@nestjs/common';
import { ResourceService } from './resource.service';
import { CreateResourceDto, UpdateResourceDto } from './dto';
import { ValidationPipe } from '../shared/pipes/validation.pipe';
import { ApiUseTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { ResponseData } from '../shared/base.interface';

const R = require('ramda');

@ApiBearerAuth()
@ApiUseTags('权限管理')
@Controller('resource')
export class ResourceController {
  constructor(private readonly resourceService: ResourceService) {}

  @ApiOperation({ title: '获取全部权限' })
  @Get()
  async findAll(): Promise<ResponseData> {
    return await this.resourceService.findAll();
  }

  @ApiOperation({ title: '创建权限' })
  @UsePipes(new ValidationPipe())
  @Post()
  async create(@Body() userData: CreateResourceDto) {
    return this.resourceService.create(userData);
  }

  @ApiOperation({ title: '根据权限id更新权限信息' })
  @UsePipes(new ValidationPipe())
  @Put()
  async update(
    @Body() resourceData: UpdateResourceDto,
  ) {
    return await this.resourceService.update(resourceData);
  }

  @ApiOperation({ title: '根据权限id删除权限信息' })
  @Delete(':resourceId')
  async delete(@Param('resourceId') resourceId: string) {
    return await this.resourceService.delete(Number(resourceId));
  }
}
